import axios from 'axios'
import React from 'react'
import { useSearchParams } from 'react-router-dom'
import { Cell, Notify } from 'react-vant'


const Payload = () => {
  const [searchParams] = useSearchParams();
  const title = searchParams.get('title')
  const id = searchParams.get('id')
  const price = searchParams.get('price')
  const handleAliPay = async () => {
    const resp = await axios.get('/api/pay', { params: { title, id, price } })
    console.log(resp.data)
    const { code, data, message } = resp.data;
    if(code === 200) {
      window.location.href = data
    } else {
      Notify.show({ type: 'danger', message })
    }
  }
  return (<div>
    <Cell title="支付宝" onClick={() => handleAliPay()}></Cell>
    <Cell title="微信"></Cell>
    <Cell title="云闪付"></Cell>
    <Cell title="翼支付"></Cell>
  </div>)
}

export default Payload